package view

import (
	"errors"
	"fmt"
	"github.com/sirupsen/logrus"
	"miao-wails/backed/app/service"
	"strconv"
)

func (a *App) GetVapHostConfig(fp string) (out service.HostConfigForm, err error) {
	out, err = service.VapServ.GetVapHostConfig(fp)
	if err != nil {
		logrus.Errorf("GetVapHostConfig err:%v", err)
		return
	}
	return
}

func (a *App) SetVapHostConfig(in service.HostConfigForm) (err error) {
	err = service.VapServ.SetVapHostConfig(in)
	if err != nil {
		logrus.Errorf("SetVapHostConfig err:%v", err)
		return
	}
	return
}

func (a *App) GetRdpPort() (port int, err error) {
	port, err = service.VapServ.GetRdpPort()
	if err != nil {
		logrus.Errorf("GetRdpPort err:%v", err)
	}
	return
}

func (a *App) SetRdpPort(port string) (err error) {
	var i int64
	i, err = strconv.ParseInt(port, 10, 64)
	if err != nil {
		logrus.Errorf("无效的端口信息：%s err:%v", port, err)
		err = errors.New(fmt.Sprintf("无效的端口信息：%s err:%v", port, err))
		return
	}
	err = service.VapServ.SetRdpPort(int(i))
	if err != nil {
		logrus.Errorf("SetRdpPort err:%v", err)
	}
	return err
}

func (a *App) GetConfigForStartType() (b bool, err error) {
	b, err = service.VapServ.GetConfigForStartType()
	if err != nil {
		logrus.Errorf("GetRdpPort err:%v", err)
	}
	return
}

func (a *App) SetConfigForStartType(b bool) (err error) {
	err = service.VapServ.SetConfigForStartType(b)
	if err != nil {
		logrus.Errorf("GetRdpPort err:%v", err)
	}
	return err
}

func (a *App) GetConfigForOldRdp() (b bool, err error) {
	b, err = service.VapServ.GetConfigForOldRdp()
	if err != nil {
		logrus.Errorf("GetRdpPort err:%v", err)
	}
	return
}

func (a *App) SetConfigForOldRdp(b bool) (err error) {
	err = service.VapServ.SetConfigForOldRdp(b)
	if err != nil {
		logrus.Errorf("GetRdpPort err:%v", err)
	}
	return
}

func (a *App) GetConfigForNetAuth() (b bool, err error) {
	b, err = service.VapServ.GetConfigForNetAuth()
	return
}
func (a *App) SetConfigForNetAuth(b bool) (err error) {
	err = service.VapServ.SetConfigForNetAuth(b)
	if err != nil {
		logrus.Errorf("SetConfigForNetAuth err:%v", err)
	}
	return err
}
func (a *App) GetConfigForCpu() (b bool, err error) {
	b, err = service.VapServ.GetConfigForCpu()
	return
}
func (a *App) SetConfigForCpu(b bool) (err error) {
	err = service.VapServ.SetConfigForCpu(b)
	if err != nil {
		logrus.Errorf("SetConfigForCpu err:%v", err)
	}
	return err
}

func (a *App) Reboot() (err error) {
	err = service.VapServ.Reboot()
	if err != nil {
		logrus.Errorf("Reboot err:%v", err)
	}
	return err
}

func (a *App) WrapCrack() (err error) {
	err = service.VapServ.WrapCrack()
	return err
}
func (a *App) GetHideDiskStatus() (b bool, err error) {
	b, err = service.VapServ.GetHideDiskStatus()
	if err != nil {
		logrus.Errorf("GetHideDiskStatus err:%v", err)
	}
	return
}
func (a *App) SetHideDiskStatus(b bool) (err error) {
	if err = service.VapServ.SetHideDisk(b); err != nil {
		logrus.Errorf("SetHideDiskStatus err:%v", err)
		return
	}
	return
}

func (a *App) GetDisabledDiskStatus() (b bool, err error) {
	b, err = service.VapServ.GetDisabledDiskStatus()
	if err != nil {
		logrus.Errorf("GetDisabledDiskStatus err:%v", err)
	}
	return
}

func (a *App) SetDisabledDiskStatus(b bool) (err error) {
	if err = service.VapServ.SetDisabledDiskStatus(b); err != nil {
		logrus.Errorf("SetDisabledDiskStatus err:%v", err)
	}
	return
}

func (a *App) KillExplorer() (err error) {
	err = service.VapServ.KillExplorer()
	if err != nil {
		logrus.Errorf("KillExplorer err:%v", err)
	}
	return err
}
func (a *App) StartExplorer() (err error) {
	err = service.VapServ.StartExplorer()
	if err != nil {
		logrus.Errorf("StartExplorer err:%v", err)
	}
	return err
}
